<template>
  <!-- 房内人员设定 -->
  <div class="door">
    <!-- 时间批量修改 -->
    <div v-if="isauth('lock_edit')">
      <div>
        <el-button type="primary" @click="createPersonnel" size="mini">添加人员</el-button>
        <b>延长授权时间:</b>
        <el-button type="primary" @click="oneDay(1)" size="mini">一天</el-button>
        <el-button type="primary" @click="oneDay(7)" size="mini">一周</el-button>
        <el-button type="primary" @click="oneDay(30)" size="mini">一月</el-button>
        <el-button type="primary" @click="oneDay(365)" size="mini">一年</el-button>
        <el-button type="primary" @click="resetTime()" size="mini">置为当前时间</el-button>
      </div>
      <!-- 星期时段批量修改 -->
      <div class="TimeWeek">
        <b>星期时段:</b>
        <span>一</span>
        <el-select
          v-model="valMonday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valMonday, 'mondayTimeStageIndex')"
        >
          <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
        </el-select>
        <span>二</span>
        <el-select
          v-model="valTuesday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valTuesday, 'tuesdayTimeStageIndex')"
        >
          <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
        </el-select>
        <span>三</span>
        <el-select
          v-model="valWednesday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valWednesday, 'wednesdayTimeStageIndex')"
        >
          <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
        </el-select>
        <span>四</span>
        <el-select
          v-model="valThursday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valThursday, 'thursdayTimeStageIndex')"
        >
          <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
        </el-select>
        <span>五</span>
        <el-select
          v-model="valFriday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valFriday, 'fridayTimeStageIndex')"
        >
          <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
        </el-select>
        <span>六</span>
        <el-select
          v-model="valSaturday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valSaturday, 'saturdayTimeStageIndex')"
        >
          <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
        </el-select>
        <span>日</span>
        <el-select
          v-model="valSunday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valSunday, 'sundayTimeStageIndex')"
        >
          <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
        </el-select>
        <b>假日时段:</b>
        <el-select
          v-model="valHoliday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valHoliday, 'holidayTimeStageIndex')"
        >
          <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
        </el-select>
      </div>
    </div>
    <!-- 房内人员信息显示 -->
    <div class="my_table">
      <el-table
        v-loading="loading"
        :data="detailslist"
        ref="table"
        border
        highlight-current-row
        style="width: 100%"
        @selection-change="cellClick"
        max-height="450"
        :header-cell-style="(header) => headFirst(header, 2)"
        :cell-style="(res) => headFirst_col(res, [], 2)"
      >
        <el-table-column type="selection" width="40px" v-if="isauth('lock_edit')" align="center"></el-table-column>

        <el-table-column
          prop="userName"
          label="姓名"
          v-if="formThead.userName.checked"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="userNumber"
          label="编号"
          v-if="formThead.userNumber.checked"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="cardNumber"
          label="卡号"
          v-if="formThead.cardNumber.checked"
          align="center"
          min-width="110px"
        ></el-table-column>
        <!-- 开始时间 -->
        <el-table-column prop="startTime" label="有效开始日期" align="center" width="190px">
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row.startTime"
              type="datetime"
              placeholder="选择日期时间"
              @change="handleSelect(scope.row, true)"
              value-format="yyyy-MM-dd HH:mm:ss"
              size="mini"
              style="width: 180px"
              :clearable="false"
              :disabled="scope.row.nameListType == 1"
            ></el-date-picker>
          </template>
        </el-table-column>
        <!-- 有效时间 -->
        <el-table-column
          prop="endTime"
          label="有效结束日期"
          v-if="formThead.endTime.checked"
          align="center"
          width="190px"
        >
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row.endTime"
              type="datetime"
              placeholder="选择日期时间"
              @change="handleSelect(scope.row)"
              value-format="yyyy-MM-dd HH:mm:ss"
              size="mini"
              style="width: 180px"
              :disabled="!isauth('lock_edit')"
              :clearable="false"
            ></el-date-picker>
          </template>
        </el-table-column>
        <el-table-column
          prop="backLock"
          label="反锁开门"
          v-if="formThead.backLock.checked"
          align="center"
          width="40px"
        >
          <template slot-scope="scope">
            <el-checkbox
              v-model="scope.row.backLock"
              :checked="scope.row.backLock"
              @change="handleChange(scope.row, 'backLock',scope.$index)"
              :disabled="!isauth('lock_edit')"
            ></el-checkbox>
          </template>
        </el-table-column>
        <!-- 开门-礼拜 -->
        <el-table-column prop="Sunday" label="星期" v-if="formThead.Sunday.checked" align="center">
          <el-table-column
            prop="monday"
            label="一"
            v-if="formThead.monday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="!isauth('lock_edit')"
                v-model="scope.row.monday"
                :checked="scope.row.monday"
                @change="handleChange(scope.row, 'monday')"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="tuesday"
            label="二"
            v-if="formThead.tuesday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="!isauth('lock_edit')"
                v-model="scope.row.tuesday"
                :checked="scope.row.tuesday"
                @change="handleChange(scope.row, 'tuesday', scope.$index)"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="wednesday"
            label="三"
            v-if="formThead.wednesday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="!isauth('lock_edit')"
                v-model="scope.row.wednesday"
                :checked="scope.row.wednesday"
                @change="handleChange(scope.row, 'wednesday')"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="thursday"
            label="四"
            v-if="formThead.thursday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="!isauth('lock_edit')"
                v-model="scope.row.thursday"
                :checked="scope.row.thursday"
                @change="handleChange(scope.row, 'thursday')"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="friday"
            label="五"
            v-if="formThead.friday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="!isauth('lock_edit')"
                v-model="scope.row.friday"
                :checked="scope.row.friday"
                @change="handleChange(scope.row, 'friday')"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="saturday"
            label="六"
            v-if="formThead.saturday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="!isauth('lock_edit')"
                v-model="scope.row.saturday"
                :checked="scope.row.saturday"
                @change="handleChange(scope.row, 'saturday')"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="sunday"
            label="日"
            v-if="formThead.sunday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="!isauth('lock_edit')"
                v-model="scope.row.sunday"
                :checked="scope.row.sunday"
                @change="handleChange(scope.row, 'sunday')"
              ></el-checkbox>
            </template>
          </el-table-column>
        </el-table-column>
        <!-- 星期时段 -->
        <el-table-column
          prop="SundayTime"
          label="星期时段"
          v-if="formThead.SundayTime.checked"
          align="center"
        >
          <el-table-column
            prop="mondayTimeStageIndex"
            label="一"
            v-if="formThead.mondayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.mondayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="!isauth('lock_edit')"
              >
                <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            prop="tuesdayTimeStageIndex"
            label="二"
            v-if="formThead.tuesdayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.tuesdayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="!isauth('lock_edit')"
              >
                <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
              </el-select>
            </template>
          </el-table-column>

          <el-table-column
            prop="wednesdayTimeStageIndex"
            label="三"
            v-if="formThead.wednesdayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.wednesdayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="!isauth('lock_edit')"
              >
                <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
              </el-select>
            </template>
          </el-table-column>

          <el-table-column
            prop="thursdayTimeStageIndex"
            label="四"
            v-if="formThead.thursdayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.thursdayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="!isauth('lock_edit')"
              >
                <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            prop="fridayTimeStageIndex"
            label="五"
            v-if="formThead.fridayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.fridayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="!isauth('lock_edit')"
              >
                <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            prop="saturdayTimeStageIndex"
            label="六"
            v-if="formThead.saturdayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.saturdayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="!isauth('lock_edit')"
              >
                <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            prop="sundayTimeStageIndex"
            label="日"
            v-if="formThead.sundayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.sundayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="!isauth('lock_edit')"
              >
                <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
              </el-select>
            </template>
          </el-table-column>
        </el-table-column>
        <!-- 假日时段 -->
        <el-table-column
          prop="holidayTimeStageIndex"
          label="假日时段"
          v-if="formThead.holidayTimeStageIndex.checked"
          align="center"
          width="82px"
        >
          <template slot-scope="scope">
            <el-select
              v-model="scope.row.holidayTimeStageIndex"
              placeholder="请选择"
              size="mini"
              @change="handleSelect(scope.row)"
              :disabled="!isauth('lock_edit')"
            >
              <el-option v-for="item in 16" :key="item - 1" :label="item - 1" :value="item - 1"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <!-- 开门密码 -->
        <el-table-column prop="doorPassword" label="开门密码" align="center" min-width="100px">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.doorPassword"
              placeholder="请输入密码"
              size="mini"
              :disabled="scope.row.nameListType == 1"
              @change="handleSelect(scope.row)"
            ></el-input>
          </template>
        </el-table-column>

        <!-- 授权状态 -->
        <el-table-column
          prop="empowerType"
          label="授权状态"
          v-if="formThead.empowerType.checked"
          align="center"
          min-width="110px"
        >
          <template slot-scope="scope">
            <span>
              {{ scope.row.updateFlag | updateFlagType
              }}{{ scope.row.downloadState | downloadStateType }}
            </span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChangepage"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="recordCount"
      ></el-pagination>
    </div>
    <!-- 房间人员设定弹窗 -->
    <add-room-jon v-if="addroomjonVisible" ref="addroomjoin" @refreshDataList="refreshDataList"></add-room-jon>
  </div>
</template>
<script>
import bus from '@/bus.js'
import AddRoomJon from './door-lock-personnel-authority-add-join'
export default {
  data() {
    return {
      loading: false,
      detailslist: [],
      pageNum: 1,
      pageSize: 10,
      currentPage: 1,
      recordCount: 0,
      searchInfo: {},
      //消费汇总
      formThead: {
        userName: {
          label: '用户',
          prop: 'userName',
          checked: true
        },
        userNumber: {
          label: '编号',
          prop: 'userNumber',
          checked: true
        },
        cardNumber: {
          label: '卡号',
          prop: 'cardNumber',
          checked: true
        },
        endTime: {
          label: '开门有效期',
          prop: 'endTime',
          checked: true
        },
        backLock: {
          label: '反锁开门',
          prop: 'backLock',
          checked: true
        },
        Sunday: {
          label: '星期',
          prop: 'backLock',
          checked: true
        },
        monday: {
          label: '星期一',
          prop: 'monday',
          checked: true
        },

        tuesday: {
          label: '星期二',
          prop: 'tuesday',
          checked: true
        },
        wednesday: {
          label: '星期三',
          prop: 'wednesday',
          checked: true
        },
        thursday: {
          label: '星期四',
          prop: 'thursday',
          checked: true
        },
        friday: {
          label: '星期五',
          prop: 'friday',
          checked: true
        },
        saturday: {
          label: '星期六',
          prop: 'saturday',
          checked: true
        },
        sunday: {
          label: '星期日',
          prop: 'sunday',
          checked: true
        },
        SundayTime: {
          label: '星期时段',
          prop: 'SundayTime',
          checked: true
        },
        mondayTimeStageIndex: {
          label: '星期一',
          prop: 'mondayTimeStageIndex',
          checked: true
        },
        tuesdayTimeStageIndex: {
          label: '星期二',
          prop: 'tuesdayTimeStageIndex',
          checked: true
        },
        wednesdayTimeStageIndex: {
          label: '星期三',
          prop: 'wednesdayTimeStageIndex',
          checked: true
        },
        thursdayTimeStageIndex: {
          label: '星期四',
          prop: 'thursdayTimeStageIndex',
          checked: true
        },
        fridayTimeStageIndex: {
          label: '星期五',
          prop: 'fridayTimeStageIndex',
          checked: true
        },
        saturdayTimeStageIndex: {
          label: '星期六',
          prop: 'saturdayTimeStageIndex',
          checked: true
        },
        sundayTimeStageIndex: {
          label: '星期七',
          prop: 'sundayTimeStageIndex',
          checked: true
        },
        holidayTimeStageIndex: {
          label: '假日时段',
          prop: 'holidayTimeStageIndex',
          checked: true
        },
        empowerType: {
          label: '授权状态',
          prop: 'empowerType',
          checked: true
        }
      },
      // 被选中的数据
      optPersonnel: [],
      // 星期时段多选
      valMonday: 0,
      valTuesday: 0,
      valWednesday: 0,
      valThursday: 0,
      valFriday: 0,
      valSaturday: 0,
      valSunday: 0,
      // 假日时段
      valHoliday: 0,
      // 添加人员弹框
      dialogVisible: false,
      addroomjonVisible: false
    }
  },
  components: {
    AddRoomJon
  },
  created() {
    this.gestatistics()
  },
  filters: {
    handleEmpowerType(empower) {
      if (empower == 0) {
        return '未授权'
      }
      if (empower == 1) {
        return '指定房间'
      }
      if (empower == 2) {
        return '临时授权'
      }
      if (empower == 2) {
        return '导入授权'
      }
    },
    updateFlagType(val) {
      val = Number(val)
      switch (val) {
        case 1:
          return '新增,'
          break
        case 2:
          return '覆盖,'
          break
        case 3:
          return '删除,'
          break
      }
    },
    downloadStateType(val) {
      val = Number(val)
      switch (val) {
        case 0:
          return '未下载'
          break
        case 1:
          return '下载成功'
          break
        case 2:
          return '设备名单已满'
          break
        case 5:
          return '名单内容有误'
          break
        case 6:
          return '找不到对应的设备'
          break
        case 7:
          return '名单已过期'
          break
      }
    }
  },
  mounted() {
    bus.$on('listenToA', this.getHeaderDate)
  },
  props: ['datetime', 'unitGuid', 'consumptionpoint', 'radio', 'roomGuid'],
  methods: {
    // 多选框是否选中
    handleChange(row, key, b) {
      // if (row[key] == false) {
      //   row[key] = true;
      // } else if (row[key] == true) {
      //   row[key] = false
      // } else if (row[key] == null) {
      //   row[key] = true
      // }
  
      if (this.optPersonnel.indexOf(row) == -1) {
        if (row) {
          this.$refs.table.toggleRowSelection(row)
        }
      }
    },
    // 选择器选中后触发，让表格选中
    handleSelect(row, is) {
      if (is && row.startTime > row.endTime) {
        this.$message({
          message: '开始时间不能大于结束时间',
          type: 'warning'
        })
        row.startTime = row.endTime
      }
      if (this.optPersonnel.indexOf(row) == -1) {
        if (row) {
          this.$refs.table.toggleRowSelection(row)
        }
      }
    },
    // 获取到房内人员授权信息
    gestatistics() {
      console.log(this.roomGuid)
      if (this.datetime == null) {
        this.searchInfo.startTime = ''
        this.searchInfo.endTime = ''
      } else {
        this.searchInfo.startTime = this.datetime[0]
        this.searchInfo.endTime = this.datetime[1]
      }
      this.searchInfo.unitGuid = this.unitGuid
      this.searchInfo.merchantGuid = this.consumptionpoint
      if (this.radio == 0) {
        this.searchInfo.timeType = 0
      } else if (this.radio == 1) {
        this.searchInfo.timeType = 1
      } else {
        this.searchInfo.timeType = 2
      }
      this.loading = true
      this.$http({
        url: this.$http.adornUrl(
          '/terminal/doorLock/room-empower-name-search-page'
        ),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            searchInfo: { roomGuid: this.roomGuid }
          },
          messageType: 0
        })
      }).then(({ data }) => {
        this.loading = false
        if (data.messageCode == 200) {
          console.log(data)
          this.detailslist = data.messageContent.data || []
          this.recordCount = data.messageContent.recordCount
          this.currentPage = data.messageContent.pageNum
          console.log(this.detailslist)
          this.detailslist.map(item => {
            item.backLock = item.backLock == 1 ? true : false
            item.friday = item.friday == 1 ? true : false
            item.monday = item.monday == 1 ? true : false
            item.saturday = item.saturday == 1 ? true : false
            item.sunday = item.sunday == 1 ? true : false
            item.thursday = item.thursday == 1 ? true : false
            item.tuesday = item.tuesday == 1 ? true : false
            item.wednesday = item.wednesday == 1 ? true : false
          })
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.gestatistics()
    },
    handleCurrentChangepage(val) {
      this.pageNum = val
      this.gestatistics()
    },
    getHeaderDate(val) {
      this.formThead = val
    },
    // 表格多选操作之后触发
    cellClick(row) {
      this.optPersonnel = row
      console.log(row)
      console.log()
      let a = row.lenght || false
      console.log(a)
      console.log(row)
      if (row.lenght != 0) {
        row.map(item => {
          if (item.updateFlag == '未授权') {
            item.backLock = 0
            item.endTime = this.getimeto('yyyy-MM-dd HH:mm:ss')
            item.friday = 0
            item.fridayTimeStageIndex = 0
            item.holidayTimeStageIndex = 0
            item.monday = 0
            item.mondayTimeStageIndex = 0
            // item.pkNamelistId = 0;
            item.saturday = 0
            item.saturdayTimeStageIndex = 0
            item.sunday = 0
            item.sundayTimeStageIndex = 0
            item.thursday = 0
            item.thursdayTimeStageIndex = 0
            item.tuesday = 0
            item.tuesdayTimeStageIndex = 0
            item.wednesday = 0
            item.wednesdayTimeStageIndex = 0
          }
        })
      }
    },
    // 增加选中人的时间
    oneDay(day) {
      if (this.optPersonnel.length == 0) {
        return false
      }
      let arr = []
      let timer = 0
      this.optPersonnel.map(item => {
        if (item.endTime) {
          timer = item.endTime
          arr = timer.split('-')
          // 月份处理
          if (day == 30) {
            if (Number(arr[1]) % 2 == 1 && Number(arr[1]) <= 7) {
              day = 31
            } else if (Number(arr[1]) == 2) {
              //判断闰年还是平年
              if (
                (Number(arr[0]) % 4 == 0 && Number(arr[0]) % 100 != 0) ||
                Number(arr[0]) % 400 == 0
              ) {
                day = 29
              } else {
                day = 28
              }
            } else if (
              Number(arr[1]) % 2 == 0 &&
              Number(arr[1]) <= 12 &&
              Number(arr[1]) > 7
            ) {
              day = 31
            }
          }
          // 年份处理
          if (day == 365) {
            //判断闰年还是平年
            if (
              (Number(arr[0]) % 4 == 0 && Number(arr[0]) % 100 != 0) ||
              Number(arr[0]) % 400 == 0
            ) {
              day = 366
            }
          }
          console.log(item.endTime)
          console.log(Number(new Date(item.endTime).getTime()))
          console.log(
            Number(new Date(item.endTime).getTime()) +
              Number(1000 * 60 * 60 * 24)
          )
          timer = new Date(
            new Date(item.endTime).getTime() + 1000 * 60 * 60 * 24 * day
          )
          console.log(timer)
          let Y = timer.getFullYear() + '-'
          let M =
            (timer.getMonth() + 1 < 10
              ? '0' + (timer.getMonth() + 1)
              : timer.getMonth() + 1) + '-'
          let D = timer.getDate() < 10 ? '0' + timer.getDate() : timer.getDate()
          let h =
            timer.getHours() < 10 ? '0' + timer.getHours() : +timer.getHours()
          let m =
            timer.getMinutes() < 10
              ? '0' + timer.getMinutes()
              : +timer.getMinutes()
          let s =
            timer.getSeconds() < 10
              ? '0' + timer.getSeconds()
              : +timer.getSeconds()
          item.endTime = Y + M + D + ' ' + h + ':' + m + ':' + s
        }
      })
    },
    // 批量重置时间
    resetTime() {
      if (this.optPersonnel.length == 0) {
        return false
      }
      this.optPersonnel.map(item => {
        item.endTime = this.getimeto('yyyy-MM-dd HH:mm:ss')
      })
    },
    // 添加人员
    createPersonnel() {
      this.dialogVisible = true
      console.log(this.unitGuid)
      console.log(1)
      this.$http({
        url: this.$http.adornUrl('/department/select-department-tree'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: this.unitGuid,
          messageType: 0
        })
      }).then(({ data }) => {
        console.log(data)
      })
    },
    // 批量修改星期时段
    handleValOne(val, key) {
      if (this.optPersonnel.length == 0) {
        return false
      }
      this.optPersonnel.map(item => {
        item[key] = val
      })
    },
    // 添加人员
    createPersonnel() {
      this.addroomjonVisible = true
      this.$nextTick(() => {
        this.$refs.addroomjoin.addinit(this.roomGuid)
      })
    },
    // 子组件方法
    childClick() {
      // 清楚不需要的参数
      let arr = JSON.parse(JSON.stringify(this.optPersonnel))
      if (arr && arr.length != 0) {
        let is = false
        arr.map(item => {
          // delete item.roomNameitem;
          // delete item.empowerType;
          // delete item.userNameitem;
          // delete item.userNumberitem;
          // delete item.cardNumberitem;
          // delete item.departmentNameitem;
          // delete item.lastUpdate;
          // // delete item.startTime;
          // delete item.downloadState;
          // delete item.updateFlagitem;
          // // delete item.cardNumber;
          // delete item.departmentName;
          // delete item.roomName;
          // delete item.updateFlag;
          // delete item.userName;
          // delete item.userNumber;
          item.backLock = item.backLock ? 1 : 0
          item.friday = item.friday ? 1 : 0
          item.monday = item.monday ? 1 : 0
          item.saturday = item.saturday ? 1 : 0
          item.sunday = item.sunday ? 1 : 0
          item.thursday = item.thursday ? 1 : 0
          item.tuesday = item.tuesday ? 1 : 0
          item.wednesday = item.wednesday ? 1 : 0
        })
        this.$http({
          url: this.$http.adornUrl(
            '/terminal/doorLock/empower-name-room-update'
          ),
          method: 'post',
          data: this.$http.adornData({
            messageContent: {
              empowerNameList: arr,
              roomGuid: this.roomGuid,
              unitGuid: this.unitGuid
            },
            messageType: 0
          })
        }).then(({ data }) => {
          console.log(data)
          if (data.messageCode == 200) {
            this.$message({
              message: '权限保存成功',
              type: 'success'
            })
            this.gestatistics()
          } else {
            this.$message.error(data.errorMessage)
          }
        })
      }
    },
    // 添加人员弹框按确定
    refreshDataList() {
      this.gestatistics()
    },
    // 弹窗关闭
    handleClose() {
      this.dialogVisible = false
    }
  }
}
</script>

<style lang="scss" scoped>
.page {
  display: flex;
  justify-content: center;
  align-items: center;
}
.door {
  // margin-left: -70px;
  //滚动条的宽度
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  //滚动条的滑块
  ::-webkit-scrollbar-thumb {
    background-color: #a1a3a9;
    border-radius: 3px;
  }
}
.TimeWeek {
  padding: 10px 0 10px 0;
}
.el-dialog--center .el-dialog__body {
  padding: 0 50px;
}
// 隐藏纵向滚动条
</style>